<template>

  <div class="space-page">
    <p>
      正在跳转，请稍等.......
    </p>
  </div>
</template>


<script setup lang="ts">

// 判断是否登录
// 登录的人是否有空间

import { useLoginUserStore } from '@/stores/useLoginUserStore.ts'
import { useRouter } from 'vue-router'
import { getSpaceVoListByPageUsingGet } from '@/api/spaceController.ts'
import { onMounted } from 'vue'
import { message } from 'ant-design-vue'

const router = useRouter()
const loginUserStore = useLoginUserStore()

const checkUserSpace = async () => {

  const loginUser = loginUserStore.loginUser

  // 登录，查看是否有空间
  const res = await getSpaceVoListByPageUsingGet({
    userId: loginUser.id,
    current: 1,
    pageSize: 1
  })

  if (res.data.code === 0) {
    // 有数据，有空间
    if (res.data.data.records.length > 0) {
      const space = res.data.data.records[0]
      router.replace(`/space/${space.id}`)
    } else {

      message.info("请先创建空间")
      router.push({
        path: '/add_space'
      })
    }
  } else {
    message.error('加载我的空间失败！' + res.data.message)
  }

}
onMounted(() => {
  checkUserSpace()
})

</script>


<style scoped>

</style>
